1539C - Stable Groups - CodeForces Solution


greedy sortings *1200

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <string>
#include<stack>
#include<unordered_set>
#include<queue>
#include<deque>
#include<algorithm>
#include <cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<iomanip> // setprecision(number)   cout << fixed << setprecision(6);
#include<ctype.h> //  towlower toupper
#define sa(a,n) sort(a,a+n)
#define endl   "\n"
#define ll long long
#define tt int
#define str string
#define fs(n)              fixed<<setprecision(n)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main() {
    fast;  
     ll n, k, xx;
     cin >> n >> k >> xx;
     vector<ll> v(n);
     for (ll x=0; x<n;x++) 
        cin >> v[x];
     sort(v.begin(),v.end());
    //...........................
    vector<ll> v2;
    ll con1 = 0,con2=0;
    for (ll x=1; x<n;x++) 
    {
        ll j= v[x] - v[x - 1];
        if (j>xx)
        {
            v2.push_back(j);
            con1++;
        }
    }
    sort(v2.begin(),v2.end());
    for (ll x=0; x<v2.size();x++) 
    {
        if(v2[x]%xx==0)//wr6 n=5  k=3 xx=2 .... 9 1 5 1 9
        v2[x]--;
        ll c =v2[x]/xx;
        if(k>=c&&k!=0)
        {
            con2++;
            k-=c;
        }
    }
    cout << ++con1 - con2 ;
     
}


Comments

Submit
0 Comments
More Questions

1611B - Team Composition Programmers and Mathematicians
110A - Nearly Lucky Number
1220B - Multiplication Table
1644A - Doors and Keys
1644B - Anti-Fibonacci Permutation
1610A - Anti Light's Cell Guessing
349B - Color the Fence
144A - Arrival of the General
1106A - Lunar New Year and Cross Counting
58A - Chat room
230A - Dragons
200B - Drinks
13A - Numbers
129A - Cookies
1367B - Even Array
136A - Presents
1450A - Avoid Trygub
327A - Flipping Game
411A - Password Check
1520C - Not Adjacent Matrix
1538B - Friends and Candies
580A - Kefa and First Steps
1038B - Non-Coprime Partition
43A - Football
50A - Domino piling
479A - Expression
1480A - Yet Another String Game
1216C - White Sheet
1648A - Weird Sum
427A - Police Recruits